﻿
using System;
using System.Collections.Generic;
using IoT3Week1.Domain;
using IoT3Week1.EfCore;
using System.Linq;  //LINQ查询

namespace IoT3Week1.App
{
    /// <summary>
    /// 接口是一种约束，
    ///  约束继承接口的类，必须实现接口规定的功能
    /// </summary>
    public class UserAppService : IUserAppService
    {
        //实例化仓储类(不需要）
        //只要做依赖注入就行了
        private readonly IRepository<User> _userRepository;

        public UserAppService(IRepository<User> userRepository)
        {
            _userRepository = userRepository; //依赖注入
        }

        public int Add(User user)
        {
            int i = _userRepository.Add(user);
            return i;
        }

        public List<User> GetUsers(string name,string pass)
        {
            List<User> list = _userRepository.GetAll();

            list = list.Where(x => x.UserName.Equals(name) && x.UserPass.Equals(pass)).ToList();

            return list;
        }
    }
}
